package single_game.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JPanel;

public class RiderPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;
	public int stamina, 
			   width,
			   height,
			   energy,
			   groupId,
			   power = 20,
			   puls = 120;
	public String name = "",
				  action = "M";
	public Color color = new Color(120, 120, 120);
	private Font font = new Font("Times New Roman", 1, 13),
				 pulsFont = new Font("Times New Roman", 1, 15),
				 powerFont = new Font("Times New Roman", 1, 20);
				  
	
	public RiderPanel(int width, int height) {
		this.width = width;
		this.height = height;
		stamina = (int)(width*0.8);
		energy = (int)(width*0.8);
	}
	
	@Override
	protected void paintComponent(Graphics g) {
	    super.paintComponent(g);     
	    
	    int startX = (int)(width*0.05); 
	    
	    g.setColor(color);  
	    g.fillRect(0,0,width, height - 10); 
	    
	    g.setColor(new Color(70, 70, 70));  
	    g.fillRect(startX, 23, (int)(width*0.8), 14); 
	    
	    g.setColor(Color.black);   
	    g.fillRect(startX, 5, (int)(width*0.8), 18); 
	    
	    g.setColor(Color.green);   
	    g.fillRect(startX, 23, stamina, 6);  
	    
	    g.setColor(Color.yellow);    
	    g.fillRect(startX, 30, energy, 6);  
	     
	    
	    g.setColor(Color.white);  
	    g.setFont(font);
	    g.drawString(name, 20, 18);

	    
	    g.setFont(powerFont);
	    g.drawString(power+"",175,35);
	    
	    String label = setGroupLabel();
	    int x = 195 - label.length()*8;
	    g.setFont(pulsFont);
	    g.drawString(label, x, 14);
	    g.drawString(action, 180, 53);
	   
	    
	    if (puls < 166)
	    	g.setColor(Color.white);  
	    else if(puls < 174)
	    	g.setColor(new Color(255, 1900-puls*10, 50));
	    else if (puls < 187)
	    	g.setColor(new Color(255, 1860-puls*10, 20));
	    else
	    	g.setColor(new Color(255, 0, 0));
	    
	   
	    g.drawString(puls+"", 80, 52);  
	  }
	
	
	private String setGroupLabel() {
		String label = "";
		if (groupId == 100 || groupId == 0) 
			label = "P";
		else if (groupId > 100)
			label = "A"+Integer.toString(groupId - 100);
		else if (groupId < 100)
			label = "E"+Integer.toString(100 - groupId);
		return label;
	}
}
